import { Component } from "@angular/core";
import { NavController,NavParams } from "ionic-angular"

import { PayresultPage } from "../payresult/payresult";
import { PayPal, PayPalPayment, PayPalConfiguration } from '@ionic-native/paypal';

@Component({
    selector: 'page-pay',
    templateUrl: 'postfee.html',
})

export class PostfeePage{
    payresultPage = PayresultPage;
    type = 1;
    info = {
        cart:'',
        price:'',
        day_price:'',
        unit:'',
        new_fee:'',
        post_fee:'',
    }
    constructor(
        private navCtl: NavController,
        private payPal: PayPal,
        private navParams: NavParams
    ) {
        this.info =  this.navParams.get('data');
    }
    _unit(item){
        switch(item){
            case 'GBP':
                return '£';
            case 'EUR':
                return '€';
            case 'USD':
                return '$';
            case 'RMB':
                return '¥';
        }
    }
    pay(){
        this.payPal.init({
            PayPalEnvironmentProduction: '',
            PayPalEnvironmentSandbox: 'AV2-K-YHJf3FgLJ3UiDNqA6z0OkZ6Y_v6OxzSBMJ5W12tBoW8K6aGVf0M6PCkDcTxz2f5jZNV_JtcZF5'
          }).then(() => {
            // Environments: PayPalEnvironmentNoNetwork, PayPalEnvironmentSandbox, PayPalEnvironmentProduction
            this.payPal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({
              // Only needed if you get an "Internal Service Error" after PayPal login!
              //payPalShippingAddressOption: 2 // PayPalShippingAddressOptionPayPal'''''
            })).then(() => {
                let payment = new PayPalPayment(this.info.price, this.info.unit, 'publish fee', 'sale');
                payment.invoiceNumber = this.info.cart+',post';
                this.payPal.renderSinglePaymentUI(payment).then((res) => {
                    alert('success!')
                    
                }, () => {
                });
            }, (err) => {
                console.log(err)
            });
          }, (err) => {
            console.log(err)
        });
    }
    
}